/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LOTTIE_C_LOTTIE_RENDER_NATIVEWINDOW_H
#define LOTTIE_C_LOTTIE_RENDER_NATIVEWINDOW_H
#include "bitmap.h"
#include "canvas.h"
#include <algorithm>
#include <native_buffer/native_buffer.h>
#include <native_drawing/drawing_types.h>
#include <native_window/external_window.h>
#include <sys/mman.h>

namespace LottieTurbo {

struct CalculatePosition {
    bool keepAspectRatio = true;
    bool crop = false;
    int width = 0;
    int height = 0;
    int x = 0;
    int y = 0;
};

class LottieRenderNativeWindow {
public:
    LottieRenderNativeWindow();
    /**
     * 渲染准备
     * @param nativeWindow
     * @param width
     * @param height
     * @return
     */
    std::shared_ptr<drawing::Canvas> PrepareRender(OHNativeWindow *nativeWindow);

    /**
     * 显示绘制结果
     * @param nativeWindow
     */
    void DisplayResult(OHNativeWindow *nativeWindow);
    
    void MunMap();

private:
    uint32_t *mappedAddr_ = nullptr;
    BufferHandle *bufferHandle_ = nullptr;
    struct NativeWindowBuffer *buffer_ = nullptr;
    int fenceFd_{-1};
    std::shared_ptr<drawing::Bitmap> bitmap_; // 改用封装类
    std::shared_ptr<drawing::Canvas> canvas_; // 改用封装类
};
} // namespace LottieTurbo

#endif // LOTTIE_C_LOTTIE_RENDER_NATIVEWINDOW_H
